#ifndef _FIG_BONE_ANIMATION_H_
#define _FIG_BONE_ANIMATION_H_


#include "fig_bonepart.h"

#include "ui/ui_sprite.h"



class FIGBoneAnimation
{
public:

	FIGBoneAnimation();
	~FIGBoneAnimation();

	struct WayPoint
	{
	  int			m_ID;
	  math::Vec2	m_Pos;

	  WayPoint() : m_ID(0)
	  {

	  }
	};

	struct	AnimatonPart
	{
		FIGBonePart*	m_pBonePart;
		math::Vec2		m_Pos;
		float			m_Rotation;
		math::Vec2		m_BackUpPos;
		float			m_BackUpRotation;

		AnimatonPart(
						FIGBonePart*		pBonePart,
						const math::Vec2&	Pos,
						float Rotation
						)  : 
						m_pBonePart(pBonePart),
						m_Rotation(Rotation),
						m_BackUpRotation(Rotation),
						m_Pos(Pos),
						m_BackUpPos(Pos)
		{
			 	 
		};

		
		
	};

	struct	AnimationStep
	{
		

		void	Clear()
		{
			for(int i = 0; i < (int) m_pAnimationParts.size(); i++)
			{
				//UTIL_SAFE_DELETE(m_pAnimationParts[i]);
			}
			m_pAnimationParts.resize(0);
		};

		std::vector<AnimatonPart*>	m_pAnimationParts;

	};


	virtual void					Tick(float dt){};
	virtual void					Render(const math::Vec2& Offset,float Scale);
	virtual void					RenderShadow(const math::Vec2& Offset,float Scale);
	virtual math::Vec2				Load(const std::string& File);

	bool							TransformForwardTick(float dt);
	bool							TransformBackwardTick(float dt);	

	void							SetColor(float R,float G,float B,float A);
	void							SetPos(const math::Vec2& Pos) { m_Pos = Pos; };
	void							SetRotation(float Rotation) { m_Rotation = Rotation; };
	
									// return size of bone (kinda)
	
	FIGBonePart*					GetBonePartByID(int ID);

	void							Reset();
	math::Vec2						GetPosByWayPoint(int WP_ID);
	const std::vector<std::string>&	GetBonePartFileNames() const { return m_BonePartFileNames; };
	std::string						GetFileName()const { return m_File; };
	void							CopyToBackup();

protected:

	FIGBonePart*					AddBonePart(
												int ID,
												const std::string& Name,
												float X,
												float Y , 
												float Rotation
												);


	bool							TransformTick(float dt,int Dir);


	std::vector<FIGBonePart*>		m_BoneParts;
	math::Vec2						m_Pos;
	float							m_Rotation;
	COLOR							m_Color;
    float							m_Radius;

	std::vector<AnimationStep*>		m_AnimatinSteps;

	int								m_CurrentStep;
					
	std::vector<WayPoint*>			m_WayPoints;
	std::string						m_File;
	std::vector<std::string>		m_BonePartFileNames;
};


#endif